<?php
	require_once(realpath(dirname(__FILE__)) . "/Baseobj.class.php");

	class Devise extends Baseobj{

		var $id;
		var $nom;
		var $code;
		var $symbole;
		var $taux;

		const TABLE="devise";
		var $table=self::TABLE;

		var $bddvars = array("id", "nom", "code", "symbole", "taux");

		function __construct($id =  0){
			parent::__construct();

			if($id  > 0)
 			  $this->charger($id);
		}

		function charger($id){
			return $this->getVars("select * from $this->table where id=\"$id\"");
		}

		function charger_nom($nom){
			return $this->getVars("select * from $this->table where nom=\"$nom\"");
		}

		function charger_symbole($symbole){
			return $this->getVars("select * from $this->table where symbole=\"$symbole\"");
		}

		function refresh(){
			$cnx = new Cnx();
			$file_contents = file_get_contents('http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml');
			$sxe = new SimpleXMLElement($file_contents);
			foreach ($sxe->Cube[0]->Cube[0]->Cube as $last)
			{
				$sql="UPDATE $this->table SET  taux='".$last["rate"]."' WHERE code='".$last["currency"]."'";
				$req=mysql_query($sql,$cnx->link);
			}
		}
	}


?>